package zb.service.imp;

import org.springframework.stereotype.Service;
import zb.pojo.Order;
import zb.service.OrderService;

import java.util.ArrayList;
import java.util.List;
@Service
public class OrderServiceimp implements OrderService {
    //静态订单集合，模拟所有订单信息
    public static List<Order>orders=new ArrayList<>();
    static {
        orders.add(new Order(1,"订单1",1,20.2));
        orders.add(new Order(2,"订单2",1,30.2));
        orders.add(new Order(3,"订单3",1,40.2));
        orders.add(new Order(4,"订单4",2,50.2));
    }
    @Override
    public List<Order> getOrderByuser(Integer uid) {
        List<Order>list=new ArrayList<>();
        //遍历
        for (Order order : orders) {
            if(order.getUid()==uid){
                list.add(order);
            }
        }
        return list;
    }

    @Override
    public Integer saveOrder(Order order) {
        orders.add(order);
        return 1;
    }

    @Override
    public Integer delOrder(Integer id) {
        //遍历
        for (Order order : orders) {
            if(order.getId()==id){
                orders.remove(order);
                return 1;
            }
        }
        return 1;
    }

    @Override
    public Integer updateOrder(Order order) {
        for (int i = 0; i < orders.size(); i++) {
            if(orders.get(i).getId()==order.getId()){
                orders.remove(orders.get(i));
                orders.add(order);
            }
        }
        return 1;
    }


}
